package com.dsiab.portalService.controller;

import com.dsiab.portalService.common.ResponseMap;
import com.dsiab.portalService.entity.CommentDto;
import com.dsiab.portalService.service.PagesSerice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
@RestController
@RequestMapping("/pages")
public class PagesController {

  @Autowired
  PagesSerice pagesSerice;

  @GetMapping("/getList/{page}")
  public ResponseMap getListPage(@PathVariable("page") String page)  {
    return ResponseMap.success(pagesSerice.getListByPage(page));
  }

  @GetMapping("/getDetail/{id}")
  public ResponseMap getDetail(@PathVariable("id") String id) {
    return ResponseMap.success(pagesSerice.getDetailByPageId(id));
  }

  @GetMapping("/getListByCatePage")
  public ResponseMap getListByCatePage(@RequestParam String cate, String page) {
    return ResponseMap.success(pagesSerice.getListByCatePage(cate,page));
  }

  @GetMapping("/getListByTagsPage")
  public ResponseMap getListByTagsPage(@RequestParam String tag, String page) throws UnsupportedEncodingException {
    return ResponseMap.success(pagesSerice.getListByTagsPage(tag,page));
  }

  @GetMapping("/getRecomList/{type}")
  public ResponseMap getRecomList(@PathVariable("type") String type) {
    return ResponseMap.success(pagesSerice.getRecomList(type));
  }

  @GetMapping("/getCate")
  public ResponseMap getCate() {
    return ResponseMap.success(pagesSerice.getCateList());
  }

  @GetMapping("/getTags")
  public ResponseMap getTags() {
    return ResponseMap.success(pagesSerice.getTagsList());
  }

  @GetMapping("/getRecommendBySameTags")
  public ResponseMap getRecommendBySameTags(@RequestParam String id) {
    return ResponseMap.success(pagesSerice.getRecommendBySameTags(id));
  }
  @GetMapping("/getTopicList")
  public ResponseMap getTopic() {
    return ResponseMap.success(pagesSerice.getTopicList());
  }

  @GetMapping("/getBasicSiteInfo")
  public ResponseMap getSiteInfo() {
    return ResponseMap.success(pagesSerice.getSiteInfo());
  }

  @GetMapping("/getTopicDetailList")
  public ResponseMap getTopicDetailList(@RequestParam String topicId) {
    return ResponseMap.success(pagesSerice.getTopicDetailList(topicId));
  }
  @PostMapping("/addComment")
  public ResponseMap addComment(@RequestBody CommentDto commentDto) {
    pagesSerice.addComment(commentDto);
    return ResponseMap.success("提交成功");
  }
  @GetMapping("/getCommentByPostId")
  public ResponseMap getCommentByPostId(@RequestParam String postId) {
    return ResponseMap.success(pagesSerice.getCommentByPostId(postId));
  }

}
